#include "StdAfx.h"
#include "DesktopGraph.h"


CDesktopGraph::CDesktopGraph(void)
{
}


CDesktopGraph::~CDesktopGraph(void)
{
}



bool CDesktopGraph::QueryInterfaces(const std::wstring & audiodevice, 
		const std::wstring& audioinput,const std::wstring& captureinput, 
		const std::wstring& filename)
{
	if (pGraph)
	{
		if(!GraphAudioDevice( audiodevice,  audioinput))
		{
			return false;
		}
		
		GUID CLSID_DeskTop;
		UuidFromString((RPC_WSTR)L"4EA6930A-2C8A-4AE6-A561-56E4B5044437", &CLSID_DeskTop);
		HRESULT hr = NOERROR;

		hr |= AddFilterByClsid(pGraph, L"DeskTop Filter", CLSID_DeskTop, &pDesktopWindows);

		hr |= AddFilterByClsid(pGraph, L"Asf Writer", CLSID_WMAsfWriter, &pBasicFile);
		hr = ConnectFilters(pGraph,pAudioDevice,pBasicFile);
		RETURN_IF_FAILED(hr);
		hr = ConnectFilters(pGraph,pDesktopWindows,pBasicFile);
		RETURN_IF_FAILED(hr);

		pBasicFile->QueryInterface(IID_IFileSinkFilter, (void**) &pFileSink);
		pFileSink->SetFileName(filename.c_str(), NULL);
		pFileSink.Release();
		hr = pGraph->QueryInterface(IID_IMediaControl, (void **) &pMediaControl);
		RETURN_IF_FAILED(hr);
		pmixer->get_MixLevel(0);


		HDC hDC;
		hDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);

		ConfigAsfWriter(GetDeviceCaps(hDC, HORZRES),
			GetDeviceCaps(hDC, VERTRES),1);


		return SUCCEEDED(hr);
	}
	return false;
}

